/*
 * @Description: 部门弹窗表单通用组件
 * @Author: Rfan
 * @Date: 2022-09-03 16:23:20
 * @LastEditTime: 2022-09-15 06:08:19
 */

import { Checkbox, Form, Input, Radio, Space, TreeSelect } from 'antd';
import { useOrgAndUserContext } from '../../../contexts/OrgAndUserContext';

const fieldNames = { label: 'deptName', value: 'id' };

function DepartmentFormItems() {
  const { departmentList } = useOrgAndUserContext();

  return (
    <>
      <Form.Item name="orgLevel" label="组织层级">
        <Radio.Group>
          <Space>
            <Radio value={1}>最高级</Radio>
            <Radio value={2}>子集</Radio>
          </Space>
        </Radio.Group>
      </Form.Item>
      <Form.Item
        noStyle
        shouldUpdate={(prevValues, currentValues) => prevValues.orgLevel !== currentValues.orgLevel}
      >
        {({ getFieldValue }) =>
          getFieldValue('orgLevel') === 2 ? (
            <Form.Item name="pid" label="父组织">
              <TreeSelect
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                placeholder="=请选择父组织="
                allowClear
                treeDefaultExpandAll
                treeData={departmentList}
                fieldNames={fieldNames}
              />
            </Form.Item>
          ) : null
        }
      </Form.Item>
      <Form.Item
        name="deptCode"
        label="组织代码"
        extra="唯一标识，必填，不能重复，字母和数字（非中文）"
      >
        <Input />
      </Form.Item>
      <Form.Item name="deptName" label="组织名称" extra="正式名称，必须填写，同级下不能重复">
        <Input />
      </Form.Item>
      <Form.Item label="组织类型" extra="当前全宗的档案部门，档案管理员只能来自于这个部门">
        <Checkbox disabled>档案部门</Checkbox>
      </Form.Item>
      <Form.Item name="isValid" label="有效状态">
        <Radio.Group>
          <Space direction="vertical">
            <Radio value={0}>有效（可正常使用）</Radio>
            <Radio value={1}>无效（不能再选中该组织，历史数据不影响）</Radio>
          </Space>
        </Radio.Group>
      </Form.Item>
      <Form.Item name="remark" label="备注">
        <Input.TextArea />
      </Form.Item>
    </>
  );
}

export default DepartmentFormItems;
